push: Support --cleanup
authorJoey Hess <joeyh@joeyh.name>
Wed, 17 May 2023 16:46:22 +0000 (12:46 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 17 May 2023 16:51:49 +0000 (12:51 -0400)
This option is not specific to sync, so it seemed it should be in either
pull or push as well as sync. Since it does modify the remote, it seems
better to have it in push; the modification of the local repo pulls in
the direction of pull, but not hard enough.

Maybe it would be better to have it in both?

Sponsored-by: Luke Shumaker on Patreon
Command/Sync.hs
doc/git-annex-push.mdwn
doc/git-annex-sync.mdwn

index ddd269fa54d9cf8fb5b30ba172ca0e25c54dbcfe..59525befe8a7c5e0d5a5fb29925576de2d100d97 100644 (file)
@@ -151,15 +151,15 @@ optParser mode desc = SyncOptions
                ( long "not-only-annex"
                <> help "operate on git branches as well as annex"
                )
-       <*> unlesssync False (switch
+       <*> unlessmode SyncMode False (switch
                ( long "commit"
                <> help "commit changes to git"
                ))
-       <*> unlesssync True (switch
+       <*> unlessmode SyncMode True (switch
                ( long "no-commit"
                <> help "avoid git commit" 
                ))
-       <*> unlesssync Nothing (optional (strOption
+       <*> unlessmode SyncMode Nothing (optional (strOption
                ( long "message" <> short 'm' <> metavar "MSG"
                <> help "commit message"
                )))
@@ -190,24 +190,22 @@ optParser mode desc = SyncOptions
                <> help "transfer contents of annexed files in a given location"
                <> metavar paramPath
                ))
-       <*> unlesssync False (switch
+       <*> unlessmode PullMode False (switch
                ( long "cleanup"
                <> help "remove synced/ branches from previous sync"
                ))
        <*> optional parseAllOption
-       <*> case mode of
-               PushMode -> pure False
-               _ -> invertableSwitch "resolvemerge" True
-                       ( help "do not automatically resolve merge conflicts"
-                       )
+       <*> unlessmode PushMode False (invertableSwitch "resolvemerge" True
+               ( help "do not automatically resolve merge conflicts"
+               ))
        <*> case mode of
                PushMode -> pure False
                _ -> parseUnrelatedHistoriesOption
        <*> pure mode
   where
-       unlesssync v a = case mode of
-               SyncMode -> a
-               _ -> pure v
+       unlessmode m v a
+               | mode /= m = a
+               | otherwise = pure v
 
 parseUnrelatedHistoriesOption :: Parser Bool
 parseUnrelatedHistoriesOption = 
index 36bebaf519062c1773e00c4f074fddc8cbbbb12a..feb3622231fdb30d363adb13091dea97bdc7292b 100644 (file)
@@ -22,11 +22,11 @@ not normally update the remote's current branch with changes from the local
 repository. (Unless the remote is configured with
 receive.denyCurrentBranch=updateInstead.)
 
-To make working with such non-bare remotes easier, this command pushes not only
-local `master` to remote `master`, but also to remote `synced/master` (and
-similar with other branches). When `git-annex pull` (or `git-annex sync`) 
-is later run on the remote, it will merge the `synced/` branches that
-were pushed to it.
+To make working with such non-bare remotes easier, this command pushes not
+only local `master` to remote `master`, but also to remote `synced/master`
+(and similar with other branches). When `git-annex pull` (or `git-annex
+sync`) is later run on the remote, it will merge the `synced/` branches
+that were pushed to it.
 
 Some special remotes allow exporting a tree of files to them,
 and this command can be used to push to those remotes as well
@@ -108,6 +108,20 @@ See [[git-annex-preferred-content]](1).
 
   Setting this to "cpus" will run one job per CPU core.
 
+* `--cleanup`
+
+  Removes the local and remote `synced/` branches, which were created
+  and pushed by `git-annex push` or `git-annex sync`. This option
+  prevents all other activities.
+
+  This can come in handy when you've pushed a change to remotes and now
+  want to reset your master branch back before that change. So you
+  run `git reset` and force-push the master branch to remotes, only
+  to find that the next `git annex merge` or `git annex pull` brings the
+  changes back. Why? Because the `synced/master` branch is hanging
+  around and still has the change in it. Cleaning up the `synced/` branches
+  prevents that problem.
+
 * Also the [[git-annex-common-options]](1) can be used.
 
 # SEE ALSO
index 96fcc17d54de45f65ddf573faa3588a64a00cbea..e2023d887301b827104db8f4901bf9cc9cfe185a 100644 (file)
@@ -61,20 +61,6 @@ content by default. This may change in a future version of git-annex.
   When `remote.<name>.annex-sync` is set to false, pushing is disabled for
   that remote, and using `--push` will not enable it.
 
-* `--cleanup`
-
-  Removes the local and remote `synced/` branches, which were created
-  and pushed by `git-annex sync`. This option prevents all other syncing
-  activities.
-
-  This can come in handy when you've synced a change to remotes and now
-  want to reset your master branch back before that change. So you
-  run `git reset` and force-push the master branch to remotes, only
-  to find that the next `git annex merge` or `git annex sync` brings the
-  changes back. Why? Because the `synced/master` branch is hanging
-  around and still has the change in it. Cleaning up the `synced/` branches
-  prevents that problem.
-
 * Also all options supported by [[git-annex-pull]](1) and
   [[git-annex-push]](1) can be used.